package cpczxt;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public abstract class HttpUtils {
	private static String ENCODING = "utf-8";

	public static String get(String url) {
		try {
			CloseableHttpClient http = HttpClients.createDefault();
			HttpGet get = new HttpGet(url);
			CloseableHttpResponse httpResponse = http.execute(get);
			HttpEntity responseEntity = httpResponse.getEntity();
			String result = EntityUtils.toString(responseEntity, ENCODING);
			EntityUtils.consume(responseEntity);
			httpResponse.close();
			http.close();
			return result;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}